package office.dao.person;

import platform.common.dao.impl.BaseDomainProviderImpl;

public class TripDP extends BaseDomainProviderImpl  {
	
	
	public String getTripForSum(){
		String hql = "from Trip where state >= ? " +
				"and " +
				"( beginDate >= ? and beginDate <= ? ) ";
		return hql;
	}
	
	public String getAllTrip(){
		String hql = "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
		"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
		"a.entryRole,a.checkRole,a.entryDate," +
		"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a,User b where " +
		"  state >= :bstate and state <= :lstate and ( beginDate >= :beginDate and beginDate <= :endDate ) and a.user.id = b.id order by a.entryDate desc ";
		return hql;
	}
	
	public String getValidateTrip(){
		String hql = "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
		"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
		"a.entryRole,a.checkRole,a.entryDate," +
		"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a,User b where " +
		"(a.user.id=:userId) and nvl(a.stopDate,a.endDate) >= :beginDate and a.user.id = b.id order by a.entryDate desc ";
		return hql;
	}
	
	
	
	public String getTripByUidAndDate(){
		String hql = "from Trip where state >= 100 and user.id = :uid and ((beginDate <= :date and endDate >= :date) or (beginDate <= :sdate and endDate >= :sdate))";
		return hql;
	}
	
	/**
	 * 获取某用户提交的或需要自己审批的请假
	 * @return
	 */
	public String getFindByUserIdCheckRole(){
		return "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
				"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
				"a.entryRole,a.checkRole,a.entryDate," +
				"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a,User b where " +
				"(a.user.id=:userId or checkRole =:checkRole) and a.user.id = b.id order by a.entryDate desc ";
	}
	
	/**
	 * 获取某用户提交的或需要自己审批的请假(销售人员、区域经理、销售经理需要限制是和自己同一部门人提交审批的记录)
	 * @return
	 */
	public String getFindByUserIdCheckRoleDept(){
		return "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
				"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
				"a.entryRole,a.checkRole,a.entryDate," +
				"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a,User b where " +
				"(a.user.id=:userId or checkRole =:checkRole) and a.user.id = b.id  and b.department.id in ( :deptId ) order by a.entryDate desc";
	}
	
	public String getFindById(){
		return "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
				"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
				"a.entryRole,a.checkRole,a.entryDate," +
				"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a where  a.id=:id";
	}
	
	public String getListTripForFinance(){
		return "select new office.action.person.form.TripForm(a.id,a.beginDate,a.endDate," +
				"a.sumTime,a.reson,a.tripMoney,a.giftName,a.user.id,a.user.cname," +
				"a.entryRole,a.checkRole,a.entryDate," +
				"a.state,a.stopDate,a.stopReson) from "+this.getDomainClassName()+" a,User b where " +
				" a.state =:state and a.user.id = b.id order by a.entryDate desc";
	}

}
